package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.xuehua.SnowflakeIdUtils;
import com.ruoyi.system.domain.dto.GradedAlarmDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GradedAlarm;
import com.ruoyi.system.service.IGradedAlarmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分级报警设置Controller
 * 
 * @author ruoyi
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/system/alarm")
public class GradedAlarmController extends BaseController
{
    @Autowired
    private IGradedAlarmService gradedAlarmService;

    /**
     * 查询分级报警设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(GradedAlarm gradedAlarm)
    {
        startPage();
        List<GradedAlarm> list = gradedAlarmService.selectGradedAlarmList(gradedAlarm);
//        GradedAlarmDto gradedAlarmDto = gradedAlarmService.selectGradedAlarmDto("200米处3号离层A基点", "顶板离层位移", "一级报警");
        return getDataTable(list);
    }

    /**
     * 查询分级报警设置列表Dto
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:list')")
    @GetMapping("/listDto")
    public TableDataInfo listDto(GradedAlarm gradedAlarm)
    {
        startPage();
        List<GradedAlarmDto> list = gradedAlarmService.selectGradedAlarmListDto(gradedAlarm);
        GradedAlarmDto gradedAlarmDto = gradedAlarmService.selectGradedAlarmDto("200米处3号离层A基点", "顶板离层位移", "一级报警");
//        gradedAlarmService.handleAlarmNormal("回风斜井回风流激光甲烷","激光甲烷","0.1");
        return getDataTable(list);
    }

    /**
     * 导出分级报警设置列表
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:export')")
    @Log(title = "分级报警设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GradedAlarm gradedAlarm)
    {
        List<GradedAlarm> list = gradedAlarmService.selectGradedAlarmList(gradedAlarm);
        ExcelUtil<GradedAlarm> util = new ExcelUtil<GradedAlarm>(GradedAlarm.class);
        util.exportExcel(response, list, "分级报警设置数据");
    }

    /**
     * 获取分级报警设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:query')")
    @GetMapping(value = "/{gradedAlarmId}")
    public AjaxResult getInfo(@PathVariable("gradedAlarmId") String gradedAlarmId)
    {
        return success(gradedAlarmService.selectGradedAlarmByGradedAlarmId(gradedAlarmId));
    }

    /**
     * 新增分级报警设置
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:add')")
    @Log(title = "分级报警设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GradedAlarm gradedAlarm)
    {
        gradedAlarm.setGradedAlarmId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(gradedAlarmService.insertGradedAlarm(gradedAlarm));
    }

    /**
     * 修改分级报警设置
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:edit')")
    @Log(title = "分级报警设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GradedAlarm gradedAlarm)
    {
        return toAjax(gradedAlarmService.updateGradedAlarm(gradedAlarm));
    }

    /**
     * 删除分级报警设置
     */
    @PreAuthorize("@ss.hasPermi('system:alarm:remove')")
    @Log(title = "分级报警设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gradedAlarmIds}")
    public AjaxResult remove(@PathVariable String[] gradedAlarmIds)
    {
        return toAjax(gradedAlarmService.deleteGradedAlarmByGradedAlarmIds(gradedAlarmIds));
    }
}
